package com.java.zhuiyun.api.course_pc.mapper;

import com.java.zhuiyun.api.course_pc.entity.FrontDeskUser;
import com.java.zhuiyun.api.course_pc.model.BackCourseModel;
import com.java.zhuiyun.api.course_pc.entity.CourseUnit;
import com.java.zhuiyun.api.order.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @InterfaceName CoursePcMapper
 * @Description TODO
 * @Author wuwan
 * @Date 2023/8/21 11:49
 **/
@Mapper
public interface CoursePcMapper {
    /*
    * @Author wuwan
    * @Description 教师查询
    * @Date 2023/8/21 16:02
    * @Return 
    * @param null
    */
    @Select("select * from teacher where id=#{id};")
    BackCourseModel getTeacher(Integer id);
    /*
    * @Author wuwan
    * @Description todo 某个老师的课程
    * @Date 2023/8/21 15:00
    * @Return
    * @param null
    */
    @Select("SELECT * FROM course JOIN teacher ON course.teacher_id = teacher.id WHERE course.del_flag = 0 AND teacher.del_flag = 0 AND course.id = #{tid} AND course_status=0;")
    List<BackCourseModel> selectCourse(Integer tid);
    /*
    * @Author wuwan
    * @Description 点击量增加
    * @Date 2023/8/23 8:38
    * @Return
    * @param null
    */
    @Update("update course set course_click = #{courseClick} where id=#{tid};")
    Integer upCourseClick(Integer tid,Integer courseClick);

    /*
     * @Author wuwan
     * @Description TODO 查询章节
     * @Date 2023/8/21 15:20
     * @Return
     * @param null
     */
    @Select("select c.*, f.file_path " +
            "FROM course_unit c,file_manager f " +
            "WHERE c.file_id = f.file_manager_id and c.del_flag = 0 and f.audit_type=1")
    List<CourseUnit> selectUnit();
    /*
     * @Author wuwan
     * @Description TODO 章节视频播放
     * @Date 2023/8/21 15:20
     * @Return
     * @param null
     */
    @Select("select c.unit_title, f.file_path FROM" +
            " course_unit c,file_manager f  " +
            "WHERE c.file_id = f.file_manager_id and c.del_flag = 0 AND c.id=#{fid} and f.audit_type=1")
    CourseUnit playVideo(Integer fid);
    /*
     * @Author wuwan
     * @Description 查询用户现有课程
     * @Date 2023/8/23 19:16
     * @Return
     * @param null
     */
    @Select("select purchase,front_desk_name from front_desk_user where id=#{uid};")
    FrontDeskUser getUserCourse(Integer uid);
    /*
    * @Author wuwan
    * @Description 课程购买 添加到用户的已购课程中
    * @Date 2023/8/23 19:16
    * @Return
    * @param null
    */
    @Update("update front_desk_user set purchase = #{purchase} where id = #{uid};")
    Integer buyCourse(Integer uid,String purchase);
    /*
    * @Author wuwan
    * @Description 查询用户信息
    * @Date 2023/8/30 11:12
    * @Return
    * @param null
    */
    @Select("select * from front_desk_user where id=#{userId}")
    FrontDeskUser queryByUser(Integer userId);
    /*
    * @Author wuwan
    * @Description 付款后修改订单状态
    * @Date 2023/8/30 14:53
    * @Return
    * @param null
    */
    @Update("update orders set order_Shipping='支付宝',order_status=0 where order_number=#{orderNumber};")
    Integer updataStatus(String orderNumber);
    /*
     * @Author wuwan
     * @Description 根据编号查询出用户id和课程id
     * @Date 2023/8/30 14:53
     * @Return
     * @param null
     */
    @Select("select user_id,course_id from orders where order_number=#{orderNumber}")
    Orders getStatus(String orderNumber);
}
